﻿package mortal.game.view.vip.panel
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.geom.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;

    public class VipOpenTipsPanel extends GSprite
    {
        private var _bg:GImageBitmap;
        protected var _tipsImg:GImageBitmap;
        protected var _vipLevel:BitmapNumberText;
        protected var _addValue:BitmapNumberText;
        protected var _vipType:int;
        protected var _valueType:int;
        protected var _isHasSecondImg:Boolean = true;
        protected var _isHasThirdImg:Boolean = false;
        protected var _isShowLeftNum:Boolean = false;
        private var _tipsPosArr:Array;
        private var _addValuePosArr:Array;
        private var _vipLevelPosArr:Array;
        private var _isGray:Boolean = false;
        private var _minLevel:int;
        public static const noValue:int = 0;
        public static const percentValue:int = 1;
        public static const numberValue:int = 2;

        public function VipOpenTipsPanel()
        {
            this._tipsPosArr = new Array();
            this._addValuePosArr = new Array();
            this._vipLevelPosArr = new Array();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.vipOpenTipsBg_mid, 0, 0, this, this.resetTipsPos1);
            this._tipsImg = UIFactory.gImageBitmap("", 0, 0, this, this.resetTipsPos);
            this._tipsImg.visible = false;
            this._vipLevel = UIFactory.bitmapNumberText(68, 9, "vipTipsNumber.png", 19, 19, -9, this, 11, BitmapNumberText.Mid);
            this._addValue = UIFactory.bitmapNumberText(0, 0, "vipTipsNumber.png", 19, 19, -9, this, 11, BitmapNumberText.Mid);
            NetDispatcher.addCmdListener(ServerCommand.VipLevelUp, this.updateInfo);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._tipsImg.dispose(param1);
            this._tipsImg = null;
            this._vipLevel.dispose(param1);
            this._vipLevel = null;
            this._addValue.dispose(param1);
            this._addValue = null;
            this._vipType = 0;
            this._isHasSecondImg = true;
            this._isHasThirdImg = false;
            this._isShowLeftNum = false;
            this._isGray = false;
            this._addValuePosArr.length = 0;
            this._vipLevelPosArr.length = 0;
            this._tipsPosArr.length = 0;
            NetDispatcher.removeCmdListener(ServerCommand.VipLevelUp, this.updateInfo);
            NetDispatcher.removeCmdListener(ServerCommand.VipFreeInfoUpdate, this.updateFreeNum);
            super.disposeImpl(param1);
            return;
        }// end function

        protected function resetTipsPos1() : void
        {
            if (isDisposed)
            {
                return;
            }
            if (this._bg)
            {
                if (this._tipsPosArr.length == 0)
                {
                    this._tipsImg.x = this._bg.width - this._tipsImg.width >> 1;
                    this._tipsImg.y = this._bg.height - this._tipsImg.height >> 1;
                }
            }
            return;
        }// end function

        protected function resetTipsPos() : void
        {
            if (isDisposed)
            {
                return;
            }
            if (this._bg)
            {
                if (this._tipsPosArr.length == 0)
                {
                    this._tipsImg.x = this._bg.width - this._tipsImg.width >> 1;
                    this._tipsImg.y = this._bg.height - this._tipsImg.height >> 1;
                }
            }
            this._tipsImg.visible = true;
            return;
        }// end function

        public function isShowLeftNum(param1:Boolean) : void
        {
            this._isShowLeftNum = param1;
            if (this._isShowLeftNum)
            {
                NetDispatcher.addCmdListener(ServerCommand.VipFreeInfoUpdate, this.updateFreeNum);
                this.updateFreeNum();
            }
            else
            {
                NetDispatcher.removeCmdListener(ServerCommand.VipFreeInfoUpdate, this.updateFreeNum);
            }
            return;
        }// end function

        public function set isHasOtherBgImg(param1:Boolean) : void
        {
            this._isHasSecondImg = param1;
            return;
        }// end function

        public function set isHasThirdImg(param1:Boolean) : void
        {
            this._isHasThirdImg = param1;
            return;
        }// end function

        public function set bgUrl(param1:String) : void
        {
            if (this._bg)
            {
                this._bg.imgUrl = param1;
            }
            return;
        }// end function

        public function set tipsUrl(param1:String) : void
        {
            if (this._tipsImg)
            {
                this._tipsImg.imgUrl = param1;
            }
            return;
        }// end function

        public function set valueType(param1:int) : void
        {
            this._valueType = param1;
            return;
        }// end function

        public function set vipType(param1:int) : void
        {
            this._vipType = param1;
            this.updateInfo();
            return;
        }// end function

        protected function updateInfo(param1:Object = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:String = null;
            var _loc_4:int = 0;
            this.visible = false;
            if (this._vipType >= 0)
            {
                _loc_2 = Cache.instance.vip.level;
                _loc_4 = this._vipType > 100 ? (this._vipType / 10) : (this._vipType);
                this._minLevel = VipUtil.getVipMinLevelByType(_loc_4);
                if (_loc_2 < this._minLevel)
                {
                    this.tipsUrl = "vipOpenTips_" + this._vipType + "_1.png";
                    this._vipLevel.text = this._minLevel + "";
                    _loc_3 = VipConfig.instance.getValueByTypeAndLv(this._vipType, this._minLevel);
                }
                else
                {
                    this._isHasSecondImg = ResourceManager.hasInfoByName("vipOpenTips_" + this._vipType + "_2.png");
                    if (this._isHasSecondImg)
                    {
                        this.tipsUrl = "vipOpenTips_" + this._vipType + "_2.png";
                    }
                    else
                    {
                        this.tipsUrl = "vipOpenTips_" + this._vipType + "_1.png";
                    }
                    this._vipLevel.text = _loc_2 + "";
                    _loc_3 = VipConfig.instance.getValueByTypeAndLv(this._vipType, _loc_2);
                }
                if (this._isShowLeftNum)
                {
                    NetDispatcher.addCmdListener(ServerCommand.VipFreeInfoUpdate, this.updateFreeNum);
                    this.updateFreeNum();
                }
                else if (int(_loc_3) > 0)
                {
                    if (this._valueType == noValue)
                    {
                        this._addValue.text = "";
                    }
                    else if (this._valueType == percentValue)
                    {
                        this._addValue.text = _loc_3 + "(";
                    }
                    else
                    {
                        this._addValue.text = _loc_3;
                    }
                }
                else
                {
                    this._addValue.text = "";
                    this._isHasThirdImg = ResourceManager.hasInfoByName("vipOpenTips_" + this._vipType + "_3.png");
                    if (int(_loc_3) == -1 && this._isHasThirdImg)
                    {
                        this.tipsUrl = "vipOpenTips_" + this._vipType + "_3.png";
                    }
                    else
                    {
                        this.tipsUrl = "vipOpenTips_" + this._vipType + "_2.png";
                    }
                }
            }
            this.changeGray();
            this.resetAllPos();
            return;
        }// end function

        private function updateFreeNum(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.vip.level;
            this._minLevel = VipUtil.getVipMinLevelByType(this._vipType);
            if (_loc_2 < this._minLevel)
            {
                this._addValue.text = VipConfig.instance.getValueByTypeAndLv(this._vipType, this._minLevel);
            }
            else
            {
                this._addValue.text = Cache.instance.vip.getLeftFreeTimesByType(this._vipType) + "";
            }
            return;
        }// end function

        private function changeGray() : void
        {
            var _loc_2:String = null;
            var _loc_1:* = Cache.instance.vip.level;
            this._minLevel = VipUtil.getVipMinLevelByType(this._vipType);
            if (_loc_1 < this._minLevel)
            {
                if (this._isGray)
                {
                    this.filters = [FilterConst.colorFilter2];
                }
                else
                {
                    this.filters = null;
                }
            }
            else
            {
                this.filters = null;
            }
            return;
        }// end function

        protected function resetAllPos() : void
        {
            this.visible = true;
            var _loc_1:* = Cache.instance.vip.level;
            this._isHasSecondImg = ResourceManager.hasInfoByName("vipOpenTips_" + this._vipType + "_2.png");
            if (_loc_1 < this._minLevel || !this._isHasSecondImg)
            {
                if (this._addValuePosArr.length)
                {
                    this._addValue.move(this._addValuePosArr[0].x, this._addValuePosArr[0].y);
                }
                if (this._vipLevelPosArr.length)
                {
                    this._vipLevel.move(this._vipLevelPosArr[0].x, this._vipLevelPosArr[0].y);
                }
                if (this._tipsPosArr.length)
                {
                    this._tipsImg.x = this._tipsPosArr[0].x;
                    this._tipsImg.y = this._tipsPosArr[0].y;
                }
            }
            else
            {
                if (this._addValuePosArr.length)
                {
                    this._addValue.move(this._addValuePosArr[1].x, this._addValuePosArr[1].y);
                }
                if (this._vipLevelPosArr.length)
                {
                    this._vipLevel.move(this._vipLevelPosArr[1].x, this._vipLevelPosArr[1].y);
                }
                if (this._tipsPosArr.length)
                {
                    this._tipsImg.x = this._tipsPosArr[1].x;
                    this._tipsImg.y = this._tipsPosArr[1].y;
                }
            }
            addChild(this._vipLevel);
            addChild(this._addValue);
            return;
        }// end function

        public function resetTipsTextPos(param1:int, param2:int, param3:int = 0, param4:int = 0) : void
        {
            this._tipsPosArr = [];
            this._tipsPosArr.push(new Point(param1, param2));
            this._tipsPosArr.push(new Point(param3, param4));
            return;
        }// end function

        public function resetValueTextPos(param1:int, param2:int, param3:int = 0, param4:int = 0) : void
        {
            this._addValuePosArr = [];
            this._addValuePosArr.push(new Point(param1, param2));
            this._addValuePosArr.push(new Point(param3, param4));
            return;
        }// end function

        public function resetLevelTextPos(param1:int, param2:int, param3:int = 0, param4:int = 0) : void
        {
            this._vipLevelPosArr = [];
            this._vipLevelPosArr.push(new Point(param1, param2));
            this._vipLevelPosArr.push(new Point(param3, param4));
            return;
        }// end function

        public function set isGray(param1:Boolean) : void
        {
            this._isGray = param1;
            return;
        }// end function

    }
}
